# $Id: PKGBUILD 89284 2013-04-28 16:20:09Z fyan $
# Maintainer: Felix Yan <felixonmars@gmail.com>
# Contributor: monson <holymonson@gmail.com>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: David Manouchehri <david@davidmanouchehri.com>

pkgname=cgminer
pkgver=3.1.0
pkgrel=1
pkgdesc="Multi-threaded multi-pool GPU, FPGA and ASIC miner for bitcoin and derivative coins"
url='http://forum.bitcoin.org/index.php?topic=28402.0'
license=('GPL3')
arch=('i686' 'x86_64')
depends=('curl' 'libcl')
makedepends=('opencl-headers')
optdepends=('opencl-nvidia: OpenCL implementation for NVIDIA'
            'opencl-catalyst: OpenCL implementation for AMD')
source=("https://github.com/ckolivas/$pkgname/archive/v$pkgver.tar.gz"
        "$pkgname.conf.d"
        "$pkgname.service")
backup=("etc/conf.d/$pkgname" "etc/$pkgname.conf")

[ "$CARCH" == "x86_64" ] && makedepends+=('yasm')

build() {
  cd "$srcdir/$pkgname-$pkgver"

  # Use in-tree jansson since it is not compatible with jansson 2.0
  #sed -e 's/^AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true)$/request_jansson=true/' -i configure.ac

  # Here you may want to use custom CFLAGS
  #export CFLAGS="-O2 -march=native -mtune=native -msse2"
  
  ./autogen.sh
  ./configure --prefix=/usr --enable-scrypt --disable-adl
  
  make
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  make DESTDIR="$pkgdir" install

  install -Dm644 "$srcdir"/$pkgname.service "$pkgdir"/usr/lib/systemd/system/$pkgname.service
  install -Dm644 "$srcdir"/$pkgname.conf.d "$pkgdir"/etc/conf.d/$pkgname
  sed 's#/usr/local/bin#/usr/bin#g' example.conf > $pkgname.conf
  install -Dm644 $pkgname.conf "$pkgdir"/etc/$pkgname.conf
}

sha512sums=('486163017b722bb38cb42dfa5c72b57ac4c96ff0584da630f985d2f22c75418284af420a325aa82419b59dca29646b66f8c678eba7a0f36dc044207ac18c9b6c'
            '99c38bc395848f9712ce172343d31f5c60f5d8ac1cfe2f48df8f3ec6c488fc275763a79c5ef36b99f32faa465b5a65284b38e8a63ef9b144075ee13971313b41'
            '3317b60c6b1f14c47d8ee636113ef40a4023ab14054129de80a37947b381fd2b647a7053f4e1bb639efa225a514e862fa531908714c34040dda2d6221dde7f5f')
